import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import mint from '@/components/mint-ui'
import todo from '@/components/todo'
import class1router from '@/components/0420router'
import class1 from '@/components/nested-routes'
import content1 from '@/components/content1'
import content2 from '@/components/content2'
import promise from '@/components/promise'
import dashboard from '@/components/dashboard'
import detail from '@/components/detail'
import joke from '@/components/joke'
import subDetail from '@/components/0427detail'
import vuex from '@/components/0428vuex'
import todo1 from '@/components/todo-vuex'
import error from '@/components/0420-404'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/error',
      name: 'error',
      component: error
    },
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path: '/mint',
      name: 'mint',
      component: mint
    },
    {
      path: '/todo',
      name: 'todo',
      component: todo
    },
    {
      path: '/0420router/:username',
      // 元信息
      meta: {
        title: 'CLASS 1'
      },
      name: 'class1router',
      component: class1router,
      // 单个路由的守卫
      beforeEnter (to, from, next) {
        window.document.title = to.meta.title
        if(localStorage.getItem('className') != 'class1') {
          alert('禁止进入！')
        }
        next()
      }
    },
    {
      path: '/class1',
      name: 'class1',
      component: class1,
      children: [
        {
          path: 'content1',
          component: content1
        },
        {
          path: 'content2',
          component: content2
        }
      ]
    },
    {
      path: '/promise',
      name: 'promise',
      component: promise
    },
    {
      path: '/dashboard',
      name: 'dashboard',
      component: dashboard
    },
    {
      path: '/detail/:sid',
      name: 'detail',
      component: detail
    },
    {
      path: '/joke',
      name: 'joke',
      component: joke,
      children: [
        {
          path: ':sid',
          name: 'subDetail',
          component: subDetail,
        }
      ]
    },
    {
      path: '/vuex',
      name: 'vuex',
      component: vuex
    },
    {
      path: '/todo1',
      name: 'todo1',
      component: todo1
    },
    {
      path: '*',
      redirect: '/error'
    },
  ]
})
